﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Sublimation
{
    public class SlotEnergy : Slot
    {
        protected Tower destination;
        protected int transmissionSpeed;
        protected EnergyRing energyRing;

        public SlotEnergy(WorldProperties worldProperties, SlotKind kind, Tower ownerTower)
            : base(worldProperties, kind, ownerTower)
        {
            transmissionSpeed = 100;
            energyRing = new EnergyRing(worldProperties, ownerTower.Position);
        }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            energyRing.Rotation = ownerTower.Rotation;
            if(destination!= null){
                if (Vector2.Distance(destination.Position, ownerTower.Position) > range)
                {
                    if (destination.NbEnergy > ownerTower.NbEnergy)
                    {
                        if (transmissionSpeed > destination.NbEnergy)
                        {
                            int temp = (destination.NbEnergy + ownerTower.NbEnergy) / 2;
                            destination.NbEnergy = temp;
                            ownerTower.NbEnergy = temp;
                        }
                        destination.NbEnergy -= transmissionSpeed;
                        ownerTower.NbEnergy += transmissionSpeed;
                    }
                    else
                    {
                        if (transmissionSpeed > ownerTower.NbEnergy)
                        {
                            int temp = (destination.NbEnergy + ownerTower.NbEnergy) / 2;
                            destination.NbEnergy = temp;
                            ownerTower.NbEnergy = temp;
                        }
                        destination.NbEnergy += transmissionSpeed;
                        ownerTower.NbEnergy -= transmissionSpeed;
                    }
                }
            }
        }
    }
}
